import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class Text {
    public static void main(String[] args) {
        String s1 ="abcd";
    }
    public static void main11(String[] args) {
        StringBuilder sb1 = new StringBuilder("hello");
        StringBuilder sb2 = sb1;
  //       追加:即尾插->字符、字符串、整形数字
        sb1.append("");  //hello
        sb1.append("world");// hello world
        sb1.append(123);// hello world123
        System.out.println(sb1);// hello world123
        System.out.println(sb1 == sb2); // true
        System.out.println(sb1.charAt(0));// 获取0号位上的字符 h
        System.out.println(sb1.length());// 获取字符串的有效长度14
        sb1.setCharAt(0,'H'); // 设置任意位置的字符 Hello world123
        sb1.insert(0, "Hello world!!!");// Hello world!!!Hello world123
        System.out.println(sb1);
        System.out.println(sb1.indexOf("Hello"));// 获取Hello第一次出现的位置
        System.out.println(sb1.lastIndexOf("hello")); // 获取hello最后一次出现的位置
        sb1.deleteCharAt(0);// 删除首字符
        sb1.delete(0,5);// 删除[0,5)范围内的字符

        String str = sb1.substring(0, 5);// 截取[0,5)区间中的字符以String的方式返回
        System.out.println(str);
        sb1.reverse();// 字符串逆转
        str=sb1.toString();// 将StringBuffer以String的方式返回
        System.out.println(str);
    }
    public static void main10(String[] args) {
        String s1 ="  hello world !   ";
        String s2=s1.trim();
        System.out.println(s2);
        System.out.println(s1);
    }
    public static void main9(String[] args) {
        String s1 ="helloworld";
        String s2=s1.substring(2,4);  //不包括4下标
        System.out.println(s2);
    }
    public static void main8(String[] args) {
        String s1="name=lishi&age=18";
        String[] s2 =s1.split("&|=");
        for (String a:s2){
            System.out.println(a);
        }
    }
    public static void main7(String[] args) {
        String s1="name=lishi&age=18";
        String[] s2 =s1.split("&");
        for (String a:s2){
            String[] ret=a.split("=");
            for (String b:ret){
                System.out.println(b);
            }
        }
    }
    public static void main6(String[] args) {
        String s1 ="191.91.91";
        String[] ret =s1.split("\\.");
        for (String s:ret) {
            System.out.println(s);
        }
    }
    public static void main5(String[] args) {
        String s1 ="hello";
        //字符串转数组
        char[] ret=s1.toCharArray();
        System.out.println(Arrays.toString(ret));
        //数组转字符串
        String s3 =new String(ret);
        System.out.println(s3);
    }
    public static void main4(String[] args) {
        String s1 ="hello";
        String s2 ="HELLO";
        System.out.println(s1.toUpperCase());
        System.out.println(s1.toLowerCase());
    }
    public static void main3(String[] args) {
        String s="abcdef";
        int ret =s.lastIndexOf('a',2);  //由于从后找，下标为0
        System.out.println(ret);
   }
   public static void main2(String[] args) {
        String s="abcdef";
        int ret =s.indexOf('a',2);  //2下标后没有a所以返回-1
        System.out.println(ret);
   }
//    public static void main(String[] args) {
//        String s="abcdef";
//        char ret =s.charAt(0);
//        System.out.println(ret);
//    }
    public static void main1(String[] args) {
        //对象放在常量池里
        String s1 ="123";
        System.out.println(s1);
        //对象放在堆区
        String s2 =new String("456");
        System.out.println(s2);
        char[] s3={'7','8','9'};
        String s4=new String(s3);
        System.out.println(s4);
    }
}
